<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<title>添加用户弹出层</title>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/imt/js/jquery-3.1.0.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/imt/js/system.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/imt/layui/layui.js"></script>
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/imt/layui/css/layui.css"
	media="all">
</head>

<body>
	<div
		style="position: relative; top: 30%; transform: translateY(20%); width: 300px; height: 200px; margin: 0 auto;">
		<form class="layui-form" id="addUserForm" action="">
			<table style="margin: 0 auto; width: 100%;">
				<tr>
					<td>用户名</td>
					<td><input type="text" class="layui-input" name="userName"
						id="username" /></td>
				</tr>
				<tr>
					<td>密码</td>
					<td><input type="password" class="layui-input" name="userPwd"
						id="password" /></td>
				</tr>
				<tr>
					<td>用户类型</td>
					<td><input type="text" class="layui-input" name="userType"
						id="userType" /></td>
				</tr>
			</table>
		</form>
		<div class="layui-btn layui-btn-small layui-btn-normal"
			style="width: 300px; margin-top: 10px;" onclick="addUser()">添加用户</div>
	</div>
</body>




<script>

	layui.use([ 'element', 'layer' ], function() {
		var $ = layui.jquery;
		var element = layui.element;
		var layer = layui.layer; //独立版的layer无需执行这一句
	});

	layui.use(['form'], function() {
		var	form = layui.form;
	});
	
	//点击添加用户按钮
	function addUser() {
		var addUserForm = new FormData($("#addUserForm")[0]);
		var url = "${pageContext.request.contextPath}/addUser";
		$.ajax({
			url : url,
			type : 'POST',
			data : addUserForm,// 
			async : false,/*  */
			contentType : false, /*  */
			processData : false,
			dataType : 'text',
			success : function(data) {
				if (data == "OK") {
					var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
					parent.layer.close(index); //再执行关闭   
					parent.tools.refresh(); // 外部调用，如子页面
					// TODO
				} else {
					layer.alert('添加失败！' + data, {
						closeBtn : 0,
						anim : 6,
						icon : 5
					});
				}
			},
			error : function(data) {
				layer.alert('添加出现异常，请稍后再试！' + JSON.stringify(data), {
					closeBtn : 0,
					anim : 6,
					icon : 5
				});
			}
		});
	}
	
	
</script>
</html>